home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / ilisp / ilisp-hi.el.z / ilisp-hi.el
Encoding:
Text File  |  1998-05-21  |  19.4 KB  |  605 lines

  1. ;;; -*- Mode: Emacs-Lisp -*-
  2.  
  3. ;;; ilisp-hi.el --
  4.  
  5. ;;; This file is part of ILISP.
  6. ;;; Version: 5.8
  7. ;;;
  8. ;;; Copyright (C) 1990, 1991, 1992, 1993 Chris McConnell
  9. ;;;               1993, 1994 Ivan Vasquez
  10. ;;;               1994, 1995, 1996 Marco Antoniotti and Rick Busdiecker
  11. ;;;               1996 Marco Antoniotti and Rick Campbell
  12. ;;;
  13. ;;; Other authors' names for which this Copyright notice also holds
  14. ;;; may appear later in this file.
  15. ;;;
  16. ;;; Send mail to 'ilisp-request@naggum.no' to be included in the
  17. ;;; ILISP mailing list. 'ilisp@naggum.no' is the general ILISP
  18. ;;; mailing list were bugs and improvements are discussed.
  19. ;;;
  20. ;;; ILISP is freely redistributable under the terms found in the file
  21. ;;; COPYING.
  22.  
  23.  
  24. ;;;
  25. ;;; ILISP high level interface functions Lisp <-> Emacs
  26. ;;;
  27.  
  28. ;;;%Eval/compile
  29. (defun lisp-send-region (start end switch message status format
  30.                    &optional handler)
  31.   "Given START, END, SWITCH, MESSAGE, STATUS, FORMAT and optional
  32. HANDLER send the region between START and END to the lisp buffer and
  33. execute the command defined by FORMAT on the region, its package and
  34. filename.  If called with a positive prefix, the results will be
  35. inserted at the end of the region.  If SWITCH is T, the command will
  36. be sent and the buffer switched to the inferior LISP buffer.  if
  37. SWITCH is 'call, a call will be inserted.  If SWITCH is 'result the
  38. result will be returned without being displayed.  Otherwise the
  39. results will be displayed in a popup window if lisp-wait-p is T and
  40. the current-prefix-arg is not '- or if lisp-wait-p is nil and the
  41. current-prefix-arg is '-.  If not displayed in a pop-up window then
  42. comint-handler will display the results in a pop-up window if they are
  43. more than one line long, or they are from an error.  STATUS will be
  44. the process status when the command is actually executing.  MESSAGE is
  45. a message to let the user know what is going on."
  46.   (if (= start end) (error "Region is empty"))
  47.   (let ((sexp (lisp-count-pairs start end ?\( ?\)))
  48.     (string (buffer-substring start end)))
  49.     (setq string
  50.       (format (ilisp-value format)
  51.           (lisp-slashify
  52.            (if (= sexp 1)
  53.                string
  54.                (format (ilisp-value 'ilisp-block-command) string)))
  55.           (lisp-buffer-package) (buffer-file-name)))
  56.     (let ((result 
  57.        (ilisp-send
  58.         string message status
  59.         (cond ((memq switch '(t call)) switch)
  60.           ((or (not (eq lisp-wait-p (lisp-minus-prefix))) 
  61.                current-prefix-arg
  62.                (eq switch 'result)) nil)
  63.           (t 'dispatch))
  64.         handler)))
  65.  
  66.       (if result
  67.       (if current-prefix-arg
  68.           (save-excursion
  69.         (goto-char end)
  70.         (insert ?\n)
  71.         (insert result))
  72.         ;; Display the output in the usual way.
  73.         (lisp-display-output result)))
  74.       result)))
  75.  
  76. ;;;%%Eval
  77. (defun eval-region-lisp (start end &optional switch message status handler)
  78.   "Evaluate the current region."
  79.   (interactive "r")
  80.   (setq message (or message 
  81.             (concat "Evaluate " (lisp-region-name start end))))
  82.   (let ((defvar (ilisp-value 'ilisp-defvar-regexp t)))
  83.     (if (and defvar
  84.          (save-excursion
  85.            (goto-char start)
  86.            (skip-chars-forward " \t\n")
  87.            (and (let ((case-fold-search t)) (looking-at defvar))
  88.             (progn (forward-sexp) (skip-chars-forward " \t\n" end)
  89.                (= (point) end)))))
  90.     (lisp-send-region start end switch message (or status 'defvar)
  91.               'ilisp-defvar-command handler)
  92.     (lisp-send-region start end switch message (or status 'eval)
  93.               'ilisp-eval-command handler))))
  94.  
  95. ;;;
  96. (defun eval-next-sexp-lisp (&optional switch)
  97.   "Evaluate the next sexp."
  98.   (interactive)
  99.   (let (start end)
  100.     (save-excursion
  101.       (setq start (point))
  102.       (forward-sexp)
  103.       (setq end (point)))
  104.     (eval-region-lisp start end switch
  105.               (format "Evaluate %s" (buffer-substring start end)))))
  106.  
  107. ;;;
  108. (defun eval-defun-lisp (&optional switch)
  109.   "Evaluate the current form."
  110.   (interactive)
  111.   (let* ((form (lisp-defun-region-and-name))
  112.      (result
  113.       (eval-region-lisp (car form) (car (cdr form)) (or switch 'result)
  114.                 (format "Evaluating %s" (car (cdr (cdr form)))))))
  115.     ;; Display the returned value. -fmw
  116.     (lisp-display-output result)))
  117.  
  118.  
  119. ;;;%%%And go
  120. (defun eval-region-and-go-lisp (start end)
  121.   "Evaluate the current region and switch to the current ILISP buffer."
  122.   (interactive "r")
  123.   (eval-region-lisp start end t))
  124.  
  125. (defun eval-next-sexp-and-go-lisp (&optional switch)
  126.   "Evaluate the next sexp and switch to the current ILISP buffer."
  127.   (interactive)
  128.   (eval-next-sexp-lisp t))
  129.  
  130. (defun eval-defun-and-go-lisp ()
  131.   "Evaluate the current defun and switch to the current ILISP buffer.
  132. With prefix, insert a call as well."
  133.   (interactive)
  134.   (eval-defun-lisp (if current-prefix-arg 
  135.                (progn
  136.              (setq current-prefix-arg nil)
  137.              'call)
  138.                t)))
  139.  
  140. ;;;%%Compile
  141. (defun compile-region-lisp (start end &optional switch message status handler)
  142.   "Compile the current region."
  143.   (interactive "r")
  144.   (lisp-send-region
  145.    start end
  146.    (or switch 'result)            ; Default to return the result.
  147.    (or message (concat "Compile " (lisp-region-name start end)))
  148.    (or status 'compile)
  149.    'ilisp-compile-command 
  150.    handler))
  151.  
  152.     
  153. ;;;
  154. (defun compile-defun-lisp (&optional switch)
  155.   "Compile the current defun or the last command in the input-ring of
  156. an ILISP buffer if no current defun."
  157.   (interactive)
  158.   (let* ((form (lisp-defun-region-and-name))
  159.      (start (car form))
  160.      (end (car (cdr form))))
  161.     (if (and (= start end) (memq major-mode ilisp-modes))
  162.     (save-excursion
  163.       (let ((form (ring-ref (ilisp-get-input-ring) 
  164.                 (ilisp-input-ring-index))))
  165.         (set-buffer "*ilisp-send*")
  166.         (delete-region (point-min) (point-max))
  167.         (insert form)
  168.         (compile-defun-lisp)))
  169.       ;; Display the value returned by the compilation. -fmw
  170.       (let* ((thing (car (cdr (cdr form))))
  171.          (result (compile-region-lisp start end (or switch 'result)
  172.                       (format "Compiling %s" thing))))
  173.     (lisp-display-output result)))))
  174.  
  175. ;;;%%%And-go
  176. (defun compile-region-and-go-lisp (start end)
  177.   "Compile the current region and switch to the current ILISP buffer."
  178.   (interactive "r")
  179.   (compile-region-lisp start end t))
  180.  
  181. (defun compile-defun-and-go-lisp ()
  182.   "Compile the current defun and switch to the current ILISP buffer."
  183.   (interactive)
  184.   (compile-defun-lisp 
  185.    (if current-prefix-arg
  186.        (progn
  187.      (setq current-prefix-arg nil)
  188.      'call)
  189.        t)))
  190.  
  191. ;;;
  192. (defun compile-file-lisp (file-name &optional extension)
  193.   "Compile a Lisp file in the current inferior LISP and go there."
  194.   (interactive (comint-get-source
  195.         "Compile Lisp file: " lisp-prev-l/c-dir/file
  196.         lisp-source-modes nil))
  197.   (comint-check-source file-name)    ; Check to see if buffer needs saved.
  198.   (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
  199.                      (file-name-nondirectory file-name)))
  200.   (ilisp-init t)
  201.   ;; Ivan's hack for ange-ftp pathnames...
  202.   (let ((file-name
  203.      (if (string-match "/.*?@.*:" file-name)
  204.          (substring file-name (match-end 0))
  205.        file-name)))
  206.     (ilisp-send
  207.      (format (ilisp-value 'ilisp-compile-file-command) file-name
  208.          (or extension (ilisp-value 'ilisp-binary-extension)))
  209.      (concat "Compile " file-name) 'compile
  210.      t)))
  211.  
  212.  
  213. ;;;
  214. (defun ilisp-compile-inits ()
  215.   "Compile the initialization files for the current inferior LISP dialect."
  216.   (interactive)
  217.   (ilisp-init t)
  218.   (let ((files (ilisp-value 'ilisp-load-inits t)))
  219.     (while files
  220.       (compile-file-lisp 
  221.        (expand-file-name (cdr (car files)) ilisp-directory)
  222.        (ilisp-value 'ilisp-init-binary-extension t))
  223.       (setq files (cdr files)))))
  224.  
  225.  
  226. ;;;
  227. (defun close-and-send-lisp ()
  228.   "Close and indent the current sexp then send it to the inferior
  229. LISP." 
  230.   (interactive)
  231.   (reindent-lisp)
  232.   (if (memq major-mode ilisp-modes)
  233.       (return-ilisp)
  234.       (eval-defun-lisp)))
  235.  
  236. ;;;%Special commands
  237. (defun describe-lisp (sexp)
  238.   "Describe the current sexp using ilisp-describe-command.  With a
  239. negative prefix, prompt for the expression.  If in an ILISP buffer,
  240. and there is no current sexp, describe ilisp-last-command."
  241.   (interactive
  242.    (list
  243.     (if (lisp-minus-prefix)
  244.     (ilisp-read "Describe: " (lisp-previous-sexp t))
  245.     (if (memq major-mode ilisp-modes)
  246.         (if (= (point)
  247.            (process-mark (get-buffer-process (current-buffer))))
  248.         (or (ilisp-value 'ilisp-last-command t)
  249.             (error "No sexp to describe."))
  250.         (lisp-previous-sexp t))
  251.         (lisp-previous-sexp t)))))
  252.   (let ((result
  253.      (ilisp-send
  254.       (format (ilisp-value 'ilisp-describe-command) 
  255.           (lisp-slashify sexp) (lisp-buffer-package))
  256.       (concat "Describe " sexp)
  257.       'describe)))
  258.     (lisp-display-output result)))
  259.  
  260. ;;;
  261. (defun inspect-lisp (sexp)
  262.   "Inspect the current sexp using ilisp-inspect-command.  With a
  263. prefix, prompt for the expression.  If in an ILISP buffer, and there
  264. is no current sexp, inspect ilisp-last-command."
  265.   (interactive
  266.    (list
  267.     (if current-prefix-arg
  268.     (ilisp-read "Inspect: " (lisp-previous-sexp t))
  269.     (if (memq major-mode ilisp-modes)
  270.         (if (= (point)
  271.            (process-mark (get-buffer-process (current-buffer))))
  272.         (or (ilisp-value 'ilisp-last-command t)
  273.             (error "No sexp to inspect."))
  274.         (lisp-previous-sexp t))
  275.         (lisp-previous-sexp t)))))
  276.   (ilisp-send
  277.    (format (ilisp-value 'ilisp-inspect-command) 
  278.        (lisp-slashify sexp) (lisp-buffer-package))
  279.    (concat "Inspect " sexp)
  280.    'inspect t))
  281.  
  282. ;;;
  283. (defun arglist-lisp (symbol)
  284.   "Return the arglist of the currently looked at function.  With a
  285. numeric prefix, the arglist will be inserted.  With a negative one,
  286. the symbol will be prompted for."
  287.   (interactive
  288.    (let* ((function (lisp-function-name)))
  289.      (list (if (lisp-minus-prefix)
  290.            (ilisp-read-symbol
  291.         (format "Arglist [%s]: " (lisp-buffer-symbol function))
  292.         function t)
  293.            function))))
  294.   (if (null symbol)
  295.       (error "No symbol")
  296.       (let* ((arglist
  297.           (ilisp-send
  298.            (format (ilisp-value 'ilisp-arglist-command)
  299.                (lisp-symbol-name symbol) 
  300.                (lisp-symbol-package symbol))
  301.            nil
  302.            'args))
  303.          (position (string-match "(" arglist)))
  304.     ;; Insert just the stuff after the open paren,
  305.     ;; but display everything the inferior lisp prints.
  306.     (cond ((and (not (ilisp-value 'comint-errorp t))
  307.             current-prefix-arg position)
  308.            (let ((temp (point)))
  309.          (insert (substring arglist (1+ position)))
  310.          (goto-char temp)))
  311.  
  312.           (t
  313.            (lisp-display-output arglist))))))
  314.  
  315.  
  316. ;;;
  317. (defun documentation-lisp (symbol type)
  318.   "Return the documentation of the previous symbol using
  319. ilisp-documentation-command.  If the symbol is at the start of a list,
  320. it is assumed to be a function, otherwise variable documentation is
  321. searched for.  With a minus prefix, prompt for the symbol and type.
  322. With a numeric prefix always return the current function call
  323. documentation."
  324.   (interactive
  325.    (if (lisp-minus-prefix)
  326.        (let* ((symbol-info (lisp-previous-symbol))
  327.           (symbol (car symbol-info))
  328.           (doc (ilisp-read-symbol 
  329.             (format "Documentation [%s]: " 
  330.                 (lisp-buffer-symbol symbol))
  331.             symbol))
  332.           (default (if (car (cdr symbol-info))
  333.                'function
  334.                'variable))
  335.           (types (ilisp-value 'ilisp-documentation-types t))
  336.           (type
  337.            (if types
  338.            (ilisp-completing-read
  339.             (if default
  340.             (format "Type [%s]: " default)
  341.             "Type: ")
  342.             types
  343.             default))))
  344.      (list doc (if (stringp type) (read type) type)))
  345.        (if current-prefix-arg
  346.        (list (lisp-function-name) 'function)
  347.        (let* ((symbol-info (lisp-previous-symbol)))
  348.          (list (car symbol-info)
  349.            (if (car (cdr symbol-info))
  350.                'function
  351.                'variable))))))
  352.   (lisp-display-output
  353.    (ilisp-send
  354.     (format (ilisp-value 'ilisp-documentation-command)
  355.         (lisp-symbol-name symbol) (lisp-symbol-package symbol) type)
  356.     (format "Documentation %s %s" type (lisp-buffer-symbol symbol))
  357.     'doc)))
  358.  
  359. ;;;%%Macroexpand
  360. (defun lisp-macroexpand-form ()
  361.   "Return the next form for macroexpanding."
  362.   (save-excursion
  363.     (skip-chars-forward " \t\n")
  364.     (let* ((begin (point))
  365.        (end (progn (forward-sexp) (point)))
  366.        (form (buffer-substring begin end)))
  367.       (list
  368.        (if (lisp-minus-prefix)
  369.        (ilisp-read "Macroexpand: " form)
  370.        form)))))
  371.  
  372. ;;;
  373. (defun macroexpand-lisp (form &optional top)
  374.   "Macroexpand the next sexp until it is no longer a macro.  With a
  375. prefix, insert into buffer."
  376.   (interactive (lisp-macroexpand-form))
  377.   (if (string-match "(\\([^ \t\n)]*\\)" form)
  378.       (let ((message (concat "Macroexpand"
  379.                  (if top "-1 " " ")
  380.                  (substring form
  381.                     (match-beginning 1)
  382.                     (match-end 1))))
  383.         result)
  384.     (setq result
  385.           (ilisp-send
  386.            (format
  387.         (ilisp-value
  388.          (if top
  389.              'ilisp-macroexpand-1-command
  390.              'ilisp-macroexpand-command))
  391.         (lisp-slashify form)
  392.         (lisp-buffer-package)
  393.         (buffer-file-name))
  394.            message 'expand))
  395.     (if current-prefix-arg
  396.         (save-excursion (forward-sexp) (insert ?\n) (insert result))
  397.         (lisp-display-output result)))
  398.       (error "Not a form: %s" form)))
  399.  
  400. (defun macroexpand-1-lisp (form)
  401.   "Macroexpand the next sexp once.  With a prefix, insert into buffer."
  402.   (interactive (lisp-macroexpand-form))
  403.   (macroexpand-lisp form t))
  404.  
  405.  
  406.  
  407. ;;;%%Trace
  408. (defun trace-defun-lisp-break (function)
  409.   "Trace FUNCTION without arg, untrace with.  Prompt for function with
  410. negative prefix.  Default function is the current defun.  
  411. Trace with :break set."
  412.   (interactive
  413.    (let ((function (lisp-defun-name)))
  414.      (if (lisp-minus-prefix)
  415.      (list (ilisp-read-symbol
  416.         (format (if current-prefix-arg 
  417.                 "Untrace [%s]: "
  418.                 "Trace [%s]: ")
  419.             (lisp-buffer-symbol function))
  420.         function
  421.         t))
  422.      (list function))))
  423.   (trace-defun-lisp-internal function (not current-prefix-arg)))
  424.  
  425. (defun trace-defun-lisp (function)
  426.   "Trace FUNCTION without arg, untrace with.  Prompt for function with
  427. negative prefix.  Default function is the current defun."
  428.   (interactive
  429.    (let ((function (lisp-defun-name)))
  430.      (if (lisp-minus-prefix)
  431.      (list (ilisp-read-symbol
  432.         (format (if current-prefix-arg 
  433.                 "Untrace [%s]: "
  434.                 "Trace [%s]: ")
  435.             (lisp-buffer-symbol function))
  436.         function
  437.         t))
  438.      (list function))))
  439.   (trace-defun-lisp-internal function nil))
  440.  
  441. (defun trace-defun-lisp-internal (function breakp)
  442.   (cond (function
  443.       (let ((result
  444.           (ilisp-send
  445.             (if current-prefix-arg
  446.             (format (ilisp-value 'ilisp-untrace-command)
  447.                 (lisp-symbol-name function)
  448.                 (lisp-symbol-package function))
  449.               (format (ilisp-value 'ilisp-trace-command)
  450.                   (lisp-symbol-name function)
  451.                   (lisp-symbol-package function)
  452.                   breakp))
  453.             (format "%srace %s" (if current-prefix-arg "Unt" "T") 
  454.                 (lisp-buffer-symbol function))
  455.             (if current-prefix-arg 'untrace 'trace)
  456.             ;; Change to always wait, so we can see the result.  -fmw, 10/13/93
  457.             ;; (if lisp-wait-p nil 'dispatch)
  458.             nil)))
  459.         ;; Display the value returned -fmw
  460.         (lisp-display-output result)))
  461.     (t
  462.       (error "No function to %strace" (if current-prefix-arg "un" "")))))
  463.  
  464.  
  465.  
  466. ;;;%%Default-directory
  467. (defun default-directory-lisp (&optional buffer)
  468.   "Set the inferior LISP default directory to the default directory of
  469. optional BUFFER.  If you are in an inferior LISP buffer, set the
  470. default directory to the current directory of the LISP."
  471.   (interactive)
  472.   (if (and (not buffer) (memq major-mode ilisp-modes))
  473.       (let ((dir
  474.          (ilisp-send
  475.           (ilisp-value 'ilisp-directory-command)
  476.           (format "Getting LISP directory")
  477.           'dir)))
  478.     (if (ilisp-value 'comint-errorp t)
  479.         (progn
  480.           (lisp-display-output dir)
  481.           (error "Error getting directory"))
  482.         (setq default-directory (read dir)
  483.           lisp-prev-l/c-dir/file (cons default-directory nil))
  484.         (message "Default directory is %s" default-directory)))
  485.       (let ((directory (save-excursion
  486.              (set-buffer (or buffer (current-buffer)))
  487.              default-directory)))
  488.     (ilisp-send 
  489.      (format (ilisp-value 'ilisp-set-directory-command) directory)
  490.      (format "Set %s's directory to %s" 
  491.          (buffer-name (ilisp-buffer)) directory)
  492.      'dir
  493.      ;; (if lisp-wait-p nil 'dispatch)
  494.      ;; The above line might cause problems with Lispworks.
  495.      ;; I just set the default to 'nil'. It shouldn't harm.
  496.      ;; Marco Antoniotti: Jan 2 1995.
  497.      ))))
  498.   
  499.  
  500. ;;;
  501. (defun load-file-lisp (file-name)
  502.   "Load a lisp file into the current inferior LISP and go there."
  503.   (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file
  504.                   lisp-source-modes nil))
  505.   (comint-check-source file-name)    ; Check to see if buffer needs saved.
  506.   (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
  507.                      (file-name-nondirectory file-name)))
  508.   (ilisp-init t)
  509.   (let* ((extension (ilisp-value 'ilisp-binary-extension t))
  510.      (binary (lisp-file-extension file-name extension)))
  511.     (save-excursion
  512.       (set-buffer (ilisp-buffer))
  513.       (if (not (eq comint-send-queue comint-end-queue))
  514.       (if (y-or-n-p "Abort commands before loading? ")
  515.           (abort-commands-lisp)
  516.           (message "Waiting for commands to finish")
  517.           (while (not (eq comint-send-queue comint-end-queue))
  518.         (accept-process-output)
  519.         (sit-for 0))))
  520.       (if (and (car (comint-send-variables (car comint-send-queue)))
  521.            (y-or-n-p "Interrupt top level? "))
  522.       (let ((result (comint-send-results (car comint-send-queue))))
  523.         (interrupt-subjob-ilisp)
  524.         (while (not (cdr result))
  525.           (accept-process-output)
  526.           (sit-for 0)))))
  527.     (if (file-newer-than-file-p file-name binary)
  528.     (if (and (not ilisp-load-no-compile-query)
  529.          extension (y-or-n-p "Compile first? "))
  530.         ;; Load binary if just compiled
  531.         (progn
  532.           (message "")
  533.           (compile-file-lisp file-name)
  534.           (setq file-name binary)))
  535.     ;; Load binary if it is current
  536.     (if (file-readable-p binary) (setq file-name binary)))
  537.     (switch-to-lisp t t)
  538.  
  539.     ;; Ivan's hack for ange-ftp pathnames...
  540.     (let ((file-name
  541.            (if (string-match "/.*?@.*:" file-name)
  542.                (substring file-name (match-end 0))
  543.                file-name)))
  544.       (comint-sender
  545.        (ilisp-process)
  546.        (format (ilisp-value 'ilisp-load-command) file-name))
  547.       (message "Loading %s" file-name))))
  548.  
  549.  
  550.  
  551. ;;;%Source
  552. ;;;%File operations
  553. ;;;
  554. (defun lisp-find-file (file &optional pop no-name)
  555.   "Find FILE, optionally POPping.
  556. If optional NO-NAME is nil, and there is a buffer with a name that is
  557. the same as the final pathname component, select that instead of
  558. reading the file associated with the full path name.  If the expanded
  559. name of FILE and buffer match, select that buffer."  
  560.  
  561.   (let* ((buffers (buffer-list))
  562.      (position 0)
  563.      (expand-symlinks t)
  564.      (expanded (expand-file-name file))
  565.      filename)
  566.     (if (not no-name)
  567.     (progn (while (string-match "/" file position)
  568.          (setq position (match-end 0)))
  569.            (setq filename (substring file position))))
  570.     (while buffers
  571.       (save-excursion 
  572.     (set-buffer (car buffers))
  573.     (let* ((name (and (not no-name) (buffer-name)))
  574.            (buffer-file (buffer-file-name))
  575.            (buffer-expanded
  576.         (cdr 
  577.          (if (string-equal buffer-file (car lisp-buffer-file)) 
  578.              lisp-buffer-file
  579.              (setq lisp-buffer-file
  580.                (cons buffer-file 
  581.                  (expand-file-name buffer-file)))))))
  582.       (if (or (and name (string-equal filename name))
  583.           (string-equal expanded buffer-expanded))
  584.           (setq file buffer-file
  585.             buffers nil)
  586.           (setq buffers (cdr buffers)))))))
  587.   (if pop
  588.       (lisp-pop-to-buffer (find-file-noselect file))
  589.       (find-file file)))
  590.  
  591. ;;;
  592. (defun find-file-lisp (file-name)
  593.   "Find a file.
  594. If point is on a string that points to an existing
  595. file, that will be the default.  If the buffer is one of
  596. lisp-source-modes, the buffer file will be the default.  Otherwise,
  597. the last file used in a lisp-source-mode will be used."
  598.   (interactive
  599.    (comint-get-source "Find file: "
  600.               lisp-prev-l/c-dir/file
  601.               lisp-source-modes nil))
  602.   (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
  603.                      (file-name-nondirectory file-name)))
  604.   (lisp-find-file file-name nil t))
  605.